package com.wlanauth.service.common.impl;

import java.io.Serializable;

import org.apache.log4j.Logger;

import com.wlanauth.core.exception.ServiceException;
import com.wlanauth.dao.common.CommonDao;
import com.wlanauth.service.common.CommonService;

public class CommonServiceImpl<T extends Serializable> implements CommonService<T> {
	
	private Logger logger = Logger.getLogger(CommonServiceImpl.class);
	
	private CommonDao<T> dao;
	
	public void save(T t)  throws ServiceException {
		try {
			this.dao.save(t);
		} catch (Exception e){
			logger.error("保存失败:"+e.getMessage(),e);
			throw new ServiceException(e);
		}
	}

	public void update(T t)  throws ServiceException {
		try {
			this.dao.update(t);
		} catch (Exception e){
			logger.error("更新失败:"+e.getMessage(),e);
			throw new ServiceException(e);
		}
	}

	public void deleteByKey(Serializable key) throws ServiceException  {
		this.dao.deleteByKey(key);
	}

	public void delete(T t) throws ServiceException  {
		this.dao.delete(t);
	}

	public T load(Serializable key) throws ServiceException  {
		return this.dao.load(key);
	}

	public T get(Serializable key) throws ServiceException  {
		return this.dao.get(key);
	}

	public void setDao(CommonDao<T> dao) throws ServiceException  {
		this.dao = dao;
	}

	public CommonDao<T> getDao() {
		return dao;
	}	
	
	
}
